package com.ys.data.auth.controller;

import com.common.pojo.Result;
import com.common.vo.RoleVo;
import com.ys.data.auth.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "角色相关API")
@RestController
@RequestMapping("role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation(value = "添加角色",notes = "添加角色")
    @PostMapping("insert")
    public Result<?> saveRole(@RequestBody RoleVo roleVo) throws Exception {
        Result result = new Result();
        result.OK(roleService.saveRole(roleVo));
        return result;
    }

    @ApiOperation(value = "更新角色",notes = "更新角色")
    @PostMapping("update")
    public Result<?> updateRole(@RequestBody RoleVo roleVo) throws Exception {
        Result result = new Result();
        result.OK(roleService.updateRole(roleVo));
        return result;
    }

    @ApiOperation(value = "查询角色",notes = "添加角色")
    @ApiImplicitParam(name = "roleId", value = "角色id", required = true, dataType = "Long")
    @GetMapping("find")
    public Result<?> findRole(@RequestParam Long roleId) throws Exception {
        Result result = new Result();
        result.OK(roleService.findRole(roleId));
        return result;
    }

    @ApiOperation(value = "删除角色",notes = "添加角色")
    @ApiImplicitParam(name = "roleId", value = "角色id", required = true, dataType = "Long")
    @DeleteMapping("delete")
    public Result<?> saveUser(@RequestParam Long roleId) throws Exception {
        Result result = new Result();
        result.OK(roleService.deleteRole(roleId));
        return result;
    }

    @ApiOperation(value = "查询角色列表",notes = "查询角色列表")
    @PostMapping("findRoles")
    public Result<?> findRoles(@RequestBody RoleVo roleVo) throws Exception {
        Result result = new Result();
        result.OK(roleService.selectRoles(roleVo));
        return result;
    }
}
